package com.foreveross.chameleon.task;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.util.EncodingUtils;

import android.os.AsyncTask;
import android.os.Environment;

import com.foreveross.chameleon.model.ModuleInfo;

public class CheckDependsTask extends
		AsyncTask<String, Integer, ArrayList<ModuleInfo>> {

	public CheckDependsTask() {
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
//		ThreadPlatformUtils.addTask2List(this);
	}

	@Override
	protected void onPostExecute(ArrayList<ModuleInfo> result) {
		super.onPostExecute(result);
//		ThreadPlatformUtils.finishTask(this);
	}

	/**
	 * @param params
	 *            [0]: String identifier; 模块唯一标识 param[1]: String path;
	 *            CubeModule.json所在路径
	 **/
	@Override
	protected ArrayList<ModuleInfo> doInBackground(String... params) {
		ArrayList<ModuleInfo> identifierList = new ArrayList<ModuleInfo>();

		return identifierList;

	}

    public static String readDependsFile(String identifier, String path) {
        String result = null;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                File s = new File(path + identifier + "/CubeModule.json");
                try {
                    FileInputStream in = new FileInputStream(s);
                    // 获取文件的字节数
                    int lenght = in.available();
                    // 创建byte数组
                    byte[] buffer = new byte[lenght];
                    // 将文件中的数据读到byte数组中
                    in.read(buffer);
                    result = EncodingUtils.getString(buffer, "UTF-8");
                } catch (Exception e) {
                }
        }
        return result;
    }
}
